package com.xm.xmapp;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.Window;

import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapNaviCameraInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
import com.amap.api.navi.model.AMapServiceAreaInfo;
import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.autonavi.tbt.TrafficFacilityInfo;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.navi.TTSController;

/**
 * 创建时间：11/10/15 15:08 项目名称：newNaviDemo
 * 
 * @author lingxiang.wang
 * @email lingxiang.wang@alibaba-inc.com 类说明：
 *        <p/>
 *        最普通的导航页面，如果你想处理一些诸如菜单点击，停止导航按钮点击的事件处理 请implement AMapNaviViewListener
 */

@SuppressWarnings("deprecation")
public class BasicNaviActivity extends BaseActivity implements
		AMapNaviViewListener, AMapNaviListener {

	protected AMapNaviView mAMapNaviView;
	protected AMapNavi mAMapNavi;
	protected TTSController mTtsManager;
	protected NaviLatLng mEndLatlng = new NaviLatLng(39.925846, 116.432765);
	protected NaviLatLng mStartLatlng = new NaviLatLng(39.925041, 116.437901);
	protected final List<NaviLatLng> sList = new ArrayList<NaviLatLng>();
	protected final List<NaviLatLng> eList = new ArrayList<NaviLatLng>();
	protected List<NaviLatLng> mWayPointList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		mTtsManager = TTSController.getInstance(getApplicationContext());
		mTtsManager.init();
		mAMapNavi = AMapNavi.getInstance(getApplicationContext());
		mAMapNavi.addAMapNaviListener(this);
		mAMapNavi.addAMapNaviListener(mTtsManager);
		// 设置模拟导航的行车速度
		mAMapNavi.setEmulatorNaviSpeed(75);
		mStartLatlng = getIntent().getParcelableExtra("mStartLatlng");
		mEndLatlng = getIntent().getParcelableExtra("mEndLatlng");

		sList.add(mStartLatlng);
		eList.add(mEndLatlng);
		setContentView(R.layout.activity_basic_navi);
		mAMapNaviView = (AMapNaviView) findViewById(R.id.navi_view);
		mAMapNaviView.onCreate(savedInstanceState);
		mAMapNaviView.setAMapNaviViewListener(this);
	}

	// /**
	// * 如果使用无起点算路，请这样写
	// */
	// private void noStartCalculate() {
	// // 无起点算路须知：
	// // AMapNavi在构造的时候，会startGPS，但是GPS启动需要一定时间
	// // 在刚构造好AMapNavi类之后立刻进行无起点算路，会立刻返回false
	// // 给人造成一种等待很久，依然没有算路成功 算路失败回调的错觉
	// // 因此，建议，提前获得AMapNavi对象实例，并判断GPS是否准备就绪
	//
	// if (mAMapNavi.isGpsReady())
	// mAMapNavi.calculateDriveRoute(mEndList, mWayPointList,
	// PathPlanningStrategy.DRIVING_DEFAULT);
	// }


	@Override
	public void onCalculateRouteSuccess(int[] ids) {
		mAMapNavi.startNavi(NaviType.GPS);
	}

	@Override
	protected void onResume() {
		super.onResume();
		mAMapNaviView.onResume();

	}

	@Override
	protected void onPause() {
		super.onPause();
		mAMapNaviView.onPause();

		// 仅仅是停止你当前在说的这句话，一会到新的路口还是会再说的
		mTtsManager.stopSpeaking();
		//
		// 停止导航之后，会触及底层stop，然后就不会再有回调了，但是讯飞当前还是没有说完的半句话还是会说完
		// mAMapNavi.stopNavi();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mAMapNaviView.onDestroy();
		mAMapNavi.stopNavi();
		mAMapNavi.destroy();
		mTtsManager.destroy();
	}

	@Override
	public void onLockMap(boolean arg0) {

	}

	@Override
	public boolean onNaviBackClick() {

		return false;
	}

	@Override
	public void onNaviCancel() {
		finish();
	}

	@Override
	public void onNaviMapMode(int arg0) {

	}

	@Override
	public void onNaviSetting() {

	}

	@Override
	public void onNaviTurnClick() {

	}

	@Override
	public void onNaviViewLoaded() {

	}

	@Override
	public void onNextRoadClick() {

	}

	@Override
	public void onScanViewButtonClick() {

	}

	@Override
	@Deprecated
	public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo arg0) {

	}

	@Override
	@Deprecated
	public void OnUpdateTrafficFacility(TrafficFacilityInfo arg0) {

	}

	@Override
	public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] arg0) {

	}

	@Override
	public void hideCross() {

	}

	@Override
	public void hideLaneInfo() {

	}

	@Override
	public void notifyParallelRoad(int arg0) {

	}

	@Override
	public void onArriveDestination() {

	}

	@Override
	public void onArrivedWayPoint(int arg0) {

	}


	@Override
	public void onCalculateRouteFailure(int arg0) {

	}

	@Override
	public void onEndEmulatorNavi() {

	}

	@Override
	public void onGetNavigationText(int arg0, String arg1) {

	}

	@Override
	public void onGpsOpenStatus(boolean arg0) {

	}

	@Override
	public void onInitNaviFailure() {

	}

	@Override
	public void onInitNaviSuccess() {

		/**
		 * 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 参数:
		 *
		 * @congestion 躲避拥堵
		 * @avoidhightspeed 不走高速
		 * @cost 避免收费
		 * @hightspeed 高速优先
		 * @multipleroute 多路径
		 *
		 *  说明: 以上参数都是boolean类型，其中multipleroute参数表示是否多条路线，如果为true则此策略会算出多条路线。
		 *  注意: 不走高速与高速优先不能同时为true 高速优先与避免收费不能同时为true
		 */
		int strategy = 0;
		try {
			//再次强调，最后一个参数为true时代表多路径，否则代表单路径
			strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
		} catch (Exception e) {
			e.printStackTrace();
		}
		mAMapNavi.setCarNumber("京", "DFZ588");
		mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);

	}

	@Override
	public void onLocationChange(AMapNaviLocation arg0) {

	}

	@Override
	public void onNaviInfoUpdate(NaviInfo arg0) {

	}

	@Override
	@Deprecated
	public void onNaviInfoUpdated(AMapNaviInfo arg0) {

	}

	@Override
	public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {

	}

	@Override
	public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {

	}

	@Override
	public void onReCalculateRouteForTrafficJam() {

	}

	@Override
	public void onReCalculateRouteForYaw() {

	}

	@Override
	public void onStartNavi(int arg0) {

	}

	@Override
	public void onTrafficStatusUpdate() {

	}

	@Override
	public void showCross(AMapNaviCross arg0) {

	}

	@Override
	public void showLaneInfo(AMapLaneInfo[] arg0, byte[] arg1, byte[] arg2) {

	}

	@Override
	public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo arg0) {

	}

	@Override
	public void onPlayRing(int i) {

	}

	@Override
	public void updateAimlessModeStatistics(AimLessModeStat arg0) {

	}


	@Override
	public void initView() {
		// TODO Auto-generated method stub

	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub

	}

	@Override
	public void initEvent() {
		// TODO Auto-generated method stub

	}

}
